<template>
  <div class="practice-container">
    <router-view v-if="$route.params.id"></router-view>
    <div v-else>
      <div class="practice-content">
        <!-- 顶部筛选区域 -->
        <div class="filter-header">
          <div class="filter-section">
            <category-nav @category-selected="handleCategorySelected" />
          </div>
          <div class="filter-section">
            <filter-section 
              @level-change="handleLevelChange" 
              @type-change="handleTypeChange" 
            />
          </div>
        </div>

        <!-- 主要内容区域 -->
        <div class="main-content">
          <!-- 左侧导航 -->
          <div class="left-sidebar">
            <div class="quick-nav">
              <div class="nav-header">
                <h3>快速导航</h3>
              </div>
              <div class="nav-content">
                <a-button-group class="nav-group">
                  <a-button @click="$router.push('/favorites')" class="nav-btn">
                    <a-icon type="star" />我的收藏
                  </a-button>
                  <a-button @click="$router.push('/record')" class="nav-btn">
                    <a-icon type="history" />答题记录
                  </a-button>
                  <a-button class="nav-btn">
                    <a-icon type="check-circle" />已完成题目
                  </a-button>
                  <a-button class="nav-btn">
                    <a-icon type="clock-circle" />未完成题目
                  </a-button>
                </a-button-group>
              </div>
            </div>

            <div class="study-tips">
              <div class="tips-header">
                <h3>学习建议</h3>
              </div>
              <div class="tips-content">
                <div class="tip-item">
                  <a-icon type="bulb" />
                  <span>按难度递进学习效果更好</span>
                </div>
                <div class="tip-item">
                  <a-icon type="schedule" />
                  <span>建议每天练习2-3道题</span>
                </div>
                <div class="tip-item">
                  <a-icon type="book" />
                  <span>做完题目多看解析和讨论</span>
                </div>
              </div>
            </div>
          </div>

          <div class="problem-list">
            <div class="list-header">
              <div class="header-top">
                <div class="header-top-left">
                  <h2>{{ selectedCategory ? selectedCategory.categoryName : '全部题目' }}</h2>
                  <span class="total-count">共 {{ total }} 题</span>
                </div>
                <div class="search-wrapper">
                  <a-input-search
                    v-model="searchText"
                    placeholder="搜索题目"
                    :enter-button="false"
                    @search="onSearch"
                    @input="handleInput"
                  >
                    <a-icon slot="prefix" type="search" />
                  </a-input-search>
                  <div 
                    v-if="showDropdown && searchResults.length > 0" 
                    class="search-dropdown"
                    @scroll="handleSearchScroll"
                  >
                    <div 
                      v-for="item in searchResults" 
                      :key="item.id" 
                      class="search-item"
                      @click="handleItemClick(item)"
                    >
                      <div class="search-item-title">
                        <a-tooltip placement="top">
                          <template slot="title">{{ item.subjectName }}</template>
                          <span class="title-text">{{ item.subjectName }}</span>
                        </a-tooltip>
                      </div>
                      <div class="search-item-tags">
                        <a-tag :class="`type-${item.subjectType}`">{{ item.subjectTypeName }}</a-tag>
                        <a-tag :class="`level-${item.subjectLevel}`">{{ item.subjectLevelName }}</a-tag>
                      </div>
                    </div>
                    <div v-if="searchLoading" class="search-loading">
                      <a-spin size="small" />
                      <span>加载中...</span>
                    </div>
                    <div v-if="!searchHasMore && searchResults.length > 0" class="search-no-more">
                      没有更多了
                    </div>
                  </div>
                </div>
              </div>
            </div>

            <a-list
              :data-source="problems"
              :loading="loading"
            >
              <a-list-item slot="renderItem" slot-scope="item" @click="goDetail(item)">
                <a-list-item-meta>
                  <template slot="title">
                    <div class="problem-title">
                      <span class="title-text">{{ item.subjectName }}</span>
                      <a-tag :class="`type-${item.subjectType}`">{{ item.subjectTypeName }}</a-tag>
                      <a-tag :class="`level-${item.subjectLevel}`">{{ item.subjectLevelName }}</a-tag>
                    </div>
                    <div class="problem-info">
                      <span class="problem-info-item">
                        <a-icon type="folder" />
                        {{ item.categoryName }}
                      </span>
                      <span class="problem-info-item">
                        <a-icon type="star" />
                        收藏数：{{ item.collectCount }}
                      </span>
                    </div>
                  </template>
                </a-list-item-meta>
                <template slot="actions">
                  <a-icon
                    v-if="!collectLoading[item.id]"
                    :type="item.isCollect === '0' ? 'star' : 'star-o'"
                    :theme="item.isCollect === '0' ? 'filled' : 'outlined'"
                    :class="['collect-icon', { active: item.isCollect === '0' }]"
                    @click.stop="handleCollect(item)"
                  />
                  <a-icon
                    v-else
                    type="loading"
                    :class="['collect-icon', 'loading']"
                    spin
                  />
                </template>
              </a-list-item>
            </a-list>
            <div class="load-more-trigger" ref="loadMoreTrigger">
              <div v-if="hasMore && !loading" class="load-more">
                <span>加载更多</span>
              </div>
              <div v-else-if="!hasMore" class="no-more">
                <span>没有更多了</span>
              </div>
            </div>
          </div>

          <div class="ranking-board">
            <div class="ranking-header">
              <h3>刷题排行榜</h3>
              <a-radio-group v-model="rankingType" size="small" button-style="solid">
                <a-radio-button value="total">总榜</a-radio-button>
              </a-radio-group>
            </div>
            <a-list :data-source="rankingList" class="ranking-list">
              <a-list-item slot="renderItem" slot-scope="item">
                <div class="ranking-item">
                  <div class="rank-number" :class="{ 'top-three': item.rank <= 3 }">{{ item.rank }}</div>
                  <a-avatar :src="item.avatar" :size="32">
                    {{ !item.avatar ? item.username.charAt(0).toUpperCase() : '' }}
                  </a-avatar>
                  <div class="user-info" @click="goToUserProfile(item.userId)">
                    <div class="user-info-content">
                      <span class="username" :title="item.username">{{ item.username }}</span>
                      <span class="solved-count">解题数：{{ item.totalRecord }}</span>
                      <span class="correct-rate">正确率：{{ item.correctRate }}%</span>
                    </div>
                  </div>
                </div>
              </a-list-item>
            </a-list>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CategoryNav from '@/components/CategoryNav'
import FilterSection from '@/components/FilterSection'
import { subject } from '@/api/subject'
import request from '@/utils/request'
export default {
  name: 'Practice',
  components: {
    CategoryNav,
    FilterSection
  },
  data() {
    return {
      selectedCategory: null,
      selectedLevel: null,
      selectedType: null,
      searchText: '',
      problems: [],
      loading: false,
      collectLoading: {},
      page: 1,
      pageSize: 10,
      total: 0,
      hasMore: true,
      rankingType: 'total',
      rankingList: [],
      loadMoreTimer: null,
      observer: null,
      searchResults: [],
      showDropdown: false,
      searchTimer: null,
      searchPage: 1,
      searchPageSize: 10,
      searchTotal: 0,
      searchHasMore: true,
      searchLoading: false,
      showBubble: false,
      bubbleTimer: null,
    }
  },
  watch: {
    rankingType: {
      handler(newVal) {
        this.fetchRankingList(newVal)
      }
    }
  },
  created() {
    this.fetchProblems()
    this.fetchRankingList()
    this.startBubbleTimer()
  },
  mounted() {
    this.initIntersectionObserver()
    document.addEventListener('click', this.handleClickOutside)
  },
  beforeDestroy() {
    if (this.loadMoreTimer) {
      clearTimeout(this.loadMoreTimer)
    }
    if (this.observer) {
      this.observer.disconnect()
    }
    document.removeEventListener('click', this.handleClickOutside)
    if (this.searchTimer) {
      clearTimeout(this.searchTimer)
    }
    if (this.bubbleTimer) {
      clearInterval(this.bubbleTimer)
    }
  },
  methods: {
    handleCategorySelected(category) {
      this.selectedCategory = category
      this.resetList()
    },
    
    handleLevelChange(level) {
      this.selectedLevel = level
      this.resetList()
    },
    
    handleTypeChange(type) {
      this.selectedType = type
      this.resetList()
    },
    
    onSearch(value) {
      this.searchText = value
      this.resetList()
    },
    
    handlePageChange(page) {
      this.page = page
      this.fetchProblems()
    },
    
    handleSizeChange(current, size) {
      this.page = 1
      this.pageSize = size
      this.fetchProblems()
    },
    
    async fetchProblems() {
      this.loading = true
      try {
        const params = {
          page: this.page,
          pageSize: this.pageSize,
          categoryId: this.selectedCategory?.id || '',
          subjectName: this.searchText,
          subjectType: this.selectedType || '',
          subjectLevel: this.selectedLevel || ''
        }
        
        const res = await subject.getPage(params)
        if (this.page === 1) {
          this.problems = res.content.list
        } else {
          this.problems = [...this.problems, ...res.content.list]
        }
        this.total = parseInt(res.content.total)
        this.hasMore = this.page * this.pageSize < this.total
        
        this.$store.dispatch('practice/initIdList', {
          ids: res.content.list.map(item => item.id),
          total: res.content.total,
          filterParams: {
            categoryId: this.selectedCategory?.id || '',
            subjectName: this.searchText,
            subjectType: this.selectedType || '',
            subjectLevel: this.selectedLevel || ''
          }
        })
      } catch (error) {
        console.log(error);
      } finally {
        this.loading = false
      }
    },
    
    async handleCollect(item) {
      if (this.collectLoading[item.id]) return;
      
      this.$set(this.collectLoading, item.id, true);
      try {
        await subject.collect(item.id)
        this.$message.success('操作成功')
        item.isCollect = item.isCollect === '0' ? '1' : '0';
        item.collectCount = item.isCollect === '0' ? 
          parseInt(item.collectCount) + 1 : 
          parseInt(item.collectCount) - 1;
      } catch (error) {
        this.$message.error('操作失败')
      } finally {
        this.$set(this.collectLoading, item.id, false);
      }
    },
    
    goDetail(item) {
      this.$router.push(`/practice/${item.id}`)
    },
    
    // 获取排行榜数据
    async fetchRankingList() {
      try {
        const res = await request.post('/subject/rank/getRankInfo', {})
        if (res.code === 200) {
          this.rankingList = res.content
        }
      } catch (error) {
        console.log(error);
        
        this.$message.error('获取排行榜数据失败')
      }
    },
    
    goToUserProfile(userId) {
      this.$router.push(`/profile/${userId}`)
    },
    
    initIntersectionObserver() {
      this.observer = new IntersectionObserver(
        (entries) => {
          const target = entries[0]
          if (target.isIntersecting && !this.loading && this.hasMore) {
            this.loadMore()
          }
        },
        {
          root: null,
          rootMargin: '100px',
          threshold: 0.1
        }
      )
      
      if (this.$refs.loadMoreTrigger) {
        this.observer.observe(this.$refs.loadMoreTrigger)
      }
    },
    
    async loadMore() {
      if (this.loading || !this.hasMore) return
      // 防抖处理，避免频繁触发
      if (this.loadMoreTimer) {
        clearTimeout(this.loadMoreTimer)
      }
      this.loadMoreTimer = setTimeout(async () => {
        this.page += 1
        await this.fetchProblems()
        
        // 获取数据后，将滚动条向上移动一点
        const problemList = this.$el.querySelector('.problem-list')
        if (problemList) {
          // 向上滚动100px，使用平滑滚动效果
          problemList.scrollTo({
            top: problemList.scrollTop - 100,
            behavior: 'smooth'
          })
        }
      }, 300)
    },
    
    resetList() {
      this.page = 1
      this.hasMore = true
      this.problems = []
      this.fetchProblems()
    },
    
    handleInput(e) {
      if (this.searchTimer) {
        clearTimeout(this.searchTimer)
      }
      
      const value = e.target.value
      this.searchTimer = setTimeout(() => {
        if (value.trim()) {
          this.searchPage = 1
          this.searchResults = []
          this.searchHasMore = true
          this.fetchSearchResults(value)
        } else {
          this.showDropdown = false
          this.searchResults = []
        }
      }, 300)
    },
    
    async fetchSearchResults(value) {
      if (this.searchLoading || !this.searchHasMore) return
      
      this.searchLoading = true
      try {
        const params = {
          page: this.searchPage,
          pageSize: this.searchPageSize,
          subjectName: value,
          categoryId: this.selectedCategory?.id || '',
          subjectType: this.selectedType || '',
          subjectLevel: this.selectedLevel || ''
        }
        
        const res = await subject.getPage(params)
        if (this.searchPage === 1) {
          this.searchResults = res.content.list
        } else {
          this.searchResults = [...this.searchResults, ...res.content.list]
        }
        
        this.searchTotal = parseInt(res.content.total)
        this.searchHasMore = this.searchPage * this.searchPageSize < this.searchTotal
        this.showDropdown = true
      } catch (error) {
        console.error('获取搜索结果失败:', error)
      } finally {
        this.searchLoading = false
      }
    },
    
    handleItemClick(item) {
      this.searchText = item.subjectName
      this.showDropdown = false
      this.goDetail(item)
    },
    
    // 添加点击外部关闭下拉框的处理
    handleClickOutside(e) {
      const searchWrapper = this.$el.querySelector('.search-wrapper')
      if (searchWrapper && !searchWrapper.contains(e.target)) {
        this.showDropdown = false
      }
    },
    
    handleSearchScroll(e) {
      const dropdown = e.target
      if (dropdown.scrollHeight - dropdown.scrollTop - dropdown.clientHeight < 50) {
        if (this.searchHasMore && !this.searchLoading) {
          this.searchPage++
          this.fetchSearchResults(this.searchText)
        }
      }
    },
    
    startBubbleTimer() {
      this.bubbleTimer = setInterval(() => {
        this.showBubble = true
        setTimeout(() => {
          this.showBubble = false
        }, 2000)
      }, 4000)
    },
    
    handleAssistantClick() {
      // 处理AI助手点击事件
      this.$router.push(`/practice/${this.$route.params.id}/analysis`)
    }
  }
}
</script>

<style scoped>
.practice-container {
  background: #fff;
  min-height: calc(100vh - 60px);
  padding: 20px;
}

.practice-content {
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.filter-header {
  background: #fff;
  border-radius: 2px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.filter-section {
  margin-bottom: 16px;
}

.filter-section:last-child {
  margin-bottom: 0;
}

.main-content {
  display: flex;
  gap: 24px;
}

.problem-list {
  flex: 1;
  min-width: 720px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ranking-board {
  width: 300px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.list-header {
  padding: 16px 24px;
  border-bottom: 1px solid #f0f0f0;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.header-top-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.total-count {
  color: #8c8c8c;
  font-size: 13px;
  position: relative;
  padding-left: 12px;
  margin-left: 4px;
}

.total-count::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background-color: #d9d9d9;
}

.search-wrapper {
  position: relative;
  width: 300px;
}

:deep(.ant-input-search) {
  width: 100%;
}

:deep(.ant-input-search .ant-input-affix-wrapper) {
  height: 36px;
  background: #f5f5f5;
  border: 1px solid transparent;
  border-radius: 18px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 16px;
}

:deep(.ant-input-search .ant-input) {
  background: transparent;
}

:deep(.ant-input-search .ant-input-prefix) {
  margin-right: 8px;
}

:deep(.ant-input-search .ant-input-prefix .anticon) {
  color: #999;
  font-size: 14px;
}

:deep(.ant-input-search .ant-input::placeholder) {
  font-size: 13px;
  color: #999;
}

:deep(.ant-input-search .ant-input-affix-wrapper:hover) {
  background: #f0f0f0;
  border-color: transparent;
}

:deep(.ant-input-search .ant-input-affix-wrapper:focus),
:deep(.ant-input-search .ant-input-affix-wrapper-focused) {
  background: #ffffff;
  border-color: #ebebeb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

:deep(.ant-input-search .ant-input-search-button) {
  display: none;
}

:deep(.ant-input-search .ant-input-suffix) {
  display: none;
}

:deep(.ant-list) {
  padding: 0;
}

:deep(.ant-list-item) {
  padding: 16px 24px !important;
  transition: all 0.3s;
  border-bottom: 1px solid #f0f0f0 !important;
  cursor: pointer;
  position: relative;
}

:deep(.ant-list-item:hover) {
  background-color: #fafafa;
}

:deep(.ant-list-item:last-child) {
  border-bottom: none !important;
}

.problem-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.title-text {
  font-size: 15px;
  color: #262626;
  font-weight: 500;
  cursor: pointer;
}

.title-text:hover {
  color: #1890ff;
}

:deep(.ant-tag) {
  margin: 0;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 20px;
  border-radius: 2px;
}

.problem-info {
  display: flex;
  gap: 24px;
  color: #8a919f;
  font-size: 13px;
  margin-top: 8px;
}

.problem-info-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

:deep(.ant-list-item-meta) {
  margin-bottom: 0;
}

:deep(.ant-list-item-meta-content) {
  width: 100%;
}

:deep(.ant-list-item-action) {
  margin-left: 48px;
}

.collect-icon {
  font-size: 16px;
  color: #8a919f;
  cursor: pointer;
  padding: 4px;
  transition: all 0.2s;
}

.collect-icon:hover {
  color: #faad14;
}

.collect-icon.active {
  color: #faad14;
}

.load-more-trigger {
  padding: 24px 0;
  text-align: center;
  border-top: 1px solid #f0f0f0;
}

.load-more {
  text-align: center;
  color: #8c8c8c;
  font-size: 14px;
  height: 32px;
  line-height: 32px;
  padding: 8px 0;
}

.no-more {
  text-align: center;
  color: #bfbfbf;
  font-size: 14px;
  height: 32px;
  line-height: 32px;
  padding: 8px 0;
}

.ranking-header {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  h3 {
    font-size: 16px;
    color: #1f2937;
  }
}

:deep(.ant-radio-group) {
  display: flex;
  gap: 8px;
}

:deep(.ant-radio-button-wrapper) {
  height: 24px;
  line-height: 22px;
  padding: 0 8px;
  font-size: 12px;
  border-color: #ebebeb;
  color: #595959;
}

:deep(.ant-radio-button-wrapper:first-child) {
  border-radius: 2px 0 0 2px;
}

:deep(.ant-radio-button-wrapper:last-child) {
  border-radius: 0 2px 2px 0;
}

:deep(.ant-radio-button-wrapper-checked) {
  color: #fff !important;
  background: #1890ff !important;
  border-color: #1890ff !important;
}

.ranking-list {
  padding: 0;
}

:deep(.ant-list-item) {
  padding: 12px 16px !important;
  transition: all 0.3s;
}

:deep(.ant-list-item:hover) {
  background-color: #f9fafb;
}

.ranking-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding-right: 8px;
}

.rank-number {
  width: 20px;
  font-size: 13px;
  color: #8a919f;
  font-weight: 600;
  text-align: center;
}

.rank-number.top-three {
  font-size: 14px;
}

.rank-number.top-three:nth-child(1) {
  color: #f5222d;
}

.rank-number.top-three:nth-child(2) {
  color: #ff7a45;
}

.rank-number.top-three:nth-child(3) {
  color: #ffa940;
}

:deep(.ant-avatar) {
  background: #1890ff;
  font-size: 14px;
}

.user-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.user-info-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.username {
  width: 80px;
  font-size: 13px;
  color: #262626;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
}

.username:hover::after {
  content: attr(title);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: -30px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 1;
}

.solved-count {
  font-size: 12px;
  color: #8a919f;
  white-space: nowrap;
  width: 90px;
}

.correct-rate {
  font-size: 12px;
  color: #52c41a;
  white-space: nowrap;
  width: 90px;
  text-align: right;
}

.user-info:hover .username {
  color: #1890ff;
}

/* 题目列表样式优化 */
:deep(.ant-list-item-meta-title) {
  margin-bottom: 8px !important;
}

.problem-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.title-text {
  font-size: 14px;
  color: #262626;
  font-weight: 500;
  cursor: pointer;
}

.title-text:hover {
  color: #1890ff;
}

:deep(.ant-tag) {
  margin: 0;
  padding: 0 6px;
  font-size: 12px;
  line-height: 20px;
  border-radius: 2px;
}

.problem-info {
  display: flex;
  gap: 16px;
  color: #8a919f;
  font-size: 12px;
}

.collect-icon {
  font-size: 14px;
  color: #8a919f;
  cursor: pointer;
  transition: all 0.2s;
}

.collect-icon:hover {
  color: #faad14;
  transform: scale(1.1);
}

.collect-icon.active {
  color: #faad14;
}

/* 分页器样式 */
.pagination {
  margin-top: 20px;
  text-align: center;
  border-top: 1px solid #f0f0f0;
  padding: 20px 0;
}

:deep(.ant-pagination-item) {
  border-radius: 4px;
  margin: 0 4px;
}

:deep(.ant-pagination-item-active) {
  border-color: #1890ff;
}

:deep(.ant-pagination-item-active a) {
  color: #1890ff;
}

:deep(.ant-input-search) {
  width: 240px;
}

:deep(.ant-input-affix-wrapper) {
  border-radius: 2px;
}

:deep(.ant-input-search-button) {
  border-radius: 0 2px 2px 0 !important;
  background-color: #1890ff;
  border-color: #1890ff;
}

:deep(.ant-input-search-button:hover) {
  background-color: #40a9ff;
  border-color: #40a9ff;
}

/* 添加与 Problems.vue 相同的标签样式 */
/* 简答题 */
.type-1 {
  color: #08979c !important;
  background: #e6fffb !important;
  border: none !important;
}

/* 选择题 */
.type-2 {
  color: #c41d7f !important;
  background: #fff0f6 !important;
  border: none !important;
}

/* 难度等级样式 */
/* 入门 */
.level-0 {
  color: #389e0d !important;
  background: #f6ffed !important;
  border: none !important;
}

/* 初级 */
.level-1 {
  color: #096dd9 !important;
  background: #e6f7ff !important;
  border: none !important;
}

/* 中级 */
.level-2 {
  color: #d46b08 !important;
  background: #fff7e6 !important;
  border: none !important;
}

/* 高级 */
.level-3 {
  color: #cf1322 !important;
  background: #fff1f0 !important;
  border: none !important;
}

/* 地狱 */
.level-4 {
  color: #531dab !important;
  background: #f9f0ff !important;
  border: none !important;
}

/* 添加分类导航的hover效果 */
:deep(.ant-menu-item) {
  margin: 4px 0 !important;
  border-radius: 4px;
}

:deep(.ant-menu-item:hover) {
  background-color: #f9fafb !important;
}

/* 搜索框样式优化 */
:deep(.ant-input-search .ant-input) {
  border-radius: 4px 0 0 4px;
}

:deep(.ant-input-search .ant-input-search-button) {
  border-radius: 0 4px 4px 0 !important;
  height: 32px;
}

.search-wrapper {
  position: relative;
  width: 320px;
  margin-left: auto;
  margin-right: 8px;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ebebeb;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
}

.search-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.3s;
  border-bottom: 1px solid #f5f5f5;

  &:last-child {
    border-bottom: none;
  }

  &:hover {
    background: #f5f7fa;
  }
}

.search-item-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 6px;

  .title-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }
}

.search-item-tags {
  display: flex;
  gap: 8px;
}

/* 自定义滚动条样式 */
.search-dropdown::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.search-dropdown::-webkit-scrollbar-track {
  background: transparent;
  border-radius: 3px;
}

.search-dropdown::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
}

.search-dropdown::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

.search-loading {
  padding: 12px;
  text-align: center;
  color: #8c8c8c;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-no-more {
  padding: 12px;
  text-align: center;
  color: #8c8c8c;
  font-size: 13px;
  border-top: 1px solid #f5f5f5;
}

.collect-icon.loading {
  color: #faad14;
  font-size: 14px;
}

.collect-icon {
  font-size: 14px;
  color: #8a919f;
  cursor: pointer;
  transition: all 0.3s;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-assistant {
  position: fixed;
  left: 40px;
  bottom: 40px;
  width: 180px;
  height: 240px;
  z-index: 1000;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.3s ease;
}

.ai-assistant:hover {
  transform: scale(1.05);
}

.assistant-container {
  position: relative;
  width: 180px;
  height: 240px;
  transform-style: preserve-3d;
}

/* AI核心样式 */
.ai-model {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: float 4s ease-in-out infinite;
}

.ai-core {
  position: absolute;
  width: 80px;
  height: 80px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
}

.core-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid transparent;
  transform-style: preserve-3d;
}

.core-ring.outer {
  width: 100%;
  height: 100%;
  border-color: rgba(0, 149, 255, 0.5);
  animation: rotate3D 8s linear infinite;
}

.core-ring.middle {
  width: 70%;
  height: 70%;
  left: 15%;
  top: 15%;
  border-color: rgba(0, 217, 255, 0.6);
  animation: rotate3D-reverse 6s linear infinite;
}

.core-ring.inner {
  width: 40%;
  height: 40%;
  left: 30%;
  top: 30%;
  border-color: rgba(0, 255, 255, 0.7);
  animation: rotate3D 4s linear infinite;
}

.core-center {
  position: absolute;
  width: 20px;
  height: 20px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 231, 255, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(0, 231, 255, 0.8);
}

.energy-ball {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, #fff, #00e7ff);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

/* 全息投影效果 */
.hologram {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.holo-lines {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.holo-line {
  position: absolute;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 231, 255, 0.5), transparent);
  animation: scanLine 2s linear infinite;
}

/* 全息对话框 */
.holo-bubble {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 200px;
  padding: 15px;
  background: rgba(0, 13, 31, 0.9);
  border: 1px solid rgba(0, 231, 255, 0.3);
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(0, 231, 255, 0.2);
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
}

.holo-bubble::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(0, 13, 31, 0.9);
}

.holo-text {
  color: #00e7ff;
  font-size: 14px;
  line-height: 1.4;
  text-shadow: 0 0 5px rgba(0, 231, 255, 0.5);
}

/* 动画效果 */
@keyframes float {
  0%, 100% { transform: translateY(0) rotateY(0); }
  50% { transform: translateY(-20px) rotateY(180deg); }
}

@keyframes rotate3D {
  0% { transform: rotateX(0) rotateY(0) rotateZ(0); }
  100% { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); }
}

@keyframes rotate3D-reverse {
  0% { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); }
  100% { transform: rotateX(0) rotateY(0) rotateZ(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes scanLine {
  0% { transform: translateY(0) translateZ(0); opacity: 0; }
  50% { transform: translateY(100%) translateZ(50px); opacity: 1; }
  100% { transform: translateY(200%) translateZ(0); opacity: 0; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .ai-assistant {
    left: 20px;
    bottom: 30px;
    transform: scale(0.8);
  }
  
  .holo-bubble {
    min-width: 180px;
  }
}

/* 左侧边栏样式 */
.left-sidebar {
  width: 240px;
  flex-shrink: 0;
}

.quick-nav,
.study-tips {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid #f0f0f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.3s ease;
}

.quick-nav:hover,
.study-tips:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.nav-header,
.tips-header {
  margin-bottom: 20px;
  position: relative;
  padding-left: 12px;
}

.nav-header::before,
.tips-header::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 16px;
  background: linear-gradient(to bottom, #1890ff, #69c0ff);
  border-radius: 2px;
}

.nav-header h3,
.tips-header h3 {
  font-size: 16px;
  color: #1f2937;
  margin: 0;
  font-weight: 600;
}

.nav-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 12px;
}

.nav-btn {
  text-align: left;
  padding: 12px 16px;
  height: auto;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  transition: all 0.3s ease;
  background: #fff;
  display: flex;
  align-items: center;
}

.nav-btn:hover {
  color: #1890ff;
  background: linear-gradient(to right, #e6f7ff, #f0f9ff);
  border-color: #91d5ff;
  transform: translateX(4px);
}

.nav-btn .anticon {
  margin-right: 10px;
  font-size: 16px;
  opacity: 0.8;
}

.nav-btn:hover .anticon {
  opacity: 1;
  transform: scale(1.1);
}

.tip-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 12px;
  transition: all 0.3s ease;
}

.tip-item:last-child {
  margin-bottom: 0;
}

.tip-item:hover {
  background: #f0f9ff;
  transform: translateX(4px);
}

.tip-item .anticon {
  color: #1890ff;
  font-size: 18px;
  margin-top: 2px;
}

.tip-item span {
  color: #4b5563;
  font-size: 14px;
  line-height: 1.5;
}

/* 主内容区域布局调整 */
.main-content {
  display: flex;
  gap: 24px;
}

.problem-list {
  flex: 1;
  min-width: 0;
}

.ranking-board {
  width: 300px;
  flex-shrink: 0;
}

/* 响应式布局调整 */
@media (max-width: 768px) {
  .practice-container {
    padding: 10px;
  }

  .main-content {
    flex-direction: column;
  }

  .left-sidebar {
    width: 100%;
    margin-bottom: 20px;
  }

  .problem-list {
    width: 100%;
  }

  .filter-header {
    padding: 10px;
  }

  .list-header {
    flex-direction: column;
    gap: 10px;
  }

  .header-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .search-wrapper {
    width: 100%;
    margin: 10px 0;
  }

  :deep(.ant-input-search) {
    width: 100%;
  }

  .problem-item {
    padding: 12px;
  }

  .problem-title {
    font-size: 14px;
  }

  .problem-info {
    flex-wrap: wrap;
    gap: 8px;
  }

  .nav-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .nav-btn {
    flex: 1;
    min-width: calc(50% - 4px);
    padding: 8px;
    font-size: 12px;
  }

  .tip-item {
    padding: 8px;
  }
}
</style> 